package com.xzit.rcpyxt.controller;

import com.xzit.rcpyxt.constant.MessageCode;
import com.xzit.rcpyxt.dto.*;
import com.xzit.rcpyxt.service.CourseClassService;
import com.xzit.rcpyxt.service.SignInService;
import com.xzit.rcpyxt.utils.PageUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/courseClass")
public class CourseClassController {

    @Autowired
    private CourseClassService courseClassService;
    @Autowired
    private SignInService signInService;

    @ApiOperation(value = "保存课程")
    @RequestMapping(value = "/saveCourseClass", method = RequestMethod.POST)
    public ResultModel saveCourseClass (@RequestBody SaveCourseClassReqeust courseClass) {
        courseClassService.saveCourseClass(courseClass);
        return new ResultModel(MessageCode.OK);
    }

    @ApiOperation(value = "修改课程状态")
    @RequestMapping(value = "/updateCourseClassStatus", method = RequestMethod.POST)
    public ResultModel saveCourseClass (@RequestBody updateCourseClassStatusRequest courseClass) {
        courseClassService.updateCourseClassStatus(courseClass);
        return new ResultModel(MessageCode.OK);
    }

    @ApiOperation(value = "获取老师对应的课程")
    @RequestMapping(value = "/findCourseClassList", method = RequestMethod.GET)
    public ResultModel findCourseClassList(CourseClassListRequest courseClassDto) {
        PageUtil byClassList = courseClassService.findCourseClassList(courseClassDto);
        return new ResultModel(MessageCode.OK, byClassList);
    }

    @ApiOperation(value = "获取学生对应的课程")
    @RequestMapping(value = "/findStudentCourseClassList", method = RequestMethod.GET)
    public ResultModel findStudentCourseClassList(StudentSourceClassRequest courseClassDto) {
        PageUtil byClassList = courseClassService.findStudentCourseClassList(courseClassDto);
        return new ResultModel(MessageCode.OK, byClassList);
    }

    @ApiOperation(value = "获取签到课程明细")
    @RequestMapping(value = "/findBySignInCourseDetail/{id}", method = RequestMethod.GET)
    public ResultModel findBySignInCourseDetail(@PathVariable int id) {
        Map byCourseDetail = courseClassService.findByCourseDetail(id);
        return new ResultModel(MessageCode.OK, byCourseDetail);
    }

    @ApiOperation(value = "获取老师签到课程列表")
    @RequestMapping(value = "/findCourseClassSignList", method = RequestMethod.GET)
    public ResultModel findCourseClassSignList(CourseClassListRequest courseClassDto) {
        PageUtil byClassList = courseClassService.findCourseClassSignList(courseClassDto);
        return new ResultModel(MessageCode.OK, byClassList);
    }

    @ApiOperation(value = "批量给老师添加课程")
    @RequestMapping(value = "/bathAddCourseClass", method = RequestMethod.GET)
    public ResultModel bathAddCourseClass(InsertCousrClassRequest courseClassDto) {
        signInService.bathAddCourseClass(courseClassDto);
        return new ResultModel(MessageCode.OK);
    }

}